Skip to content

test(v0952): robust capture of cli print output#34

Draft
HugoMachadoRodrigues wants to merge 1 commit into
mainfrom
claude/fix-v0952-vignette-print
Draft

test(v0952): robust capture of cli print output#34
HugoMachadoRodrigues wants to merge 1 commit into
mainfrom
claude/fix-v0952-vignette-print

Conversation

@HugoMachadoRodrigues
Copy link
Copy Markdown
Owner

Summary

  • Two assertions in tests/testthat/test-v0952-vignette-pt.R:86-87 failed locally on Rscript -e 'pkgload::load_all(".") + testthat::test_dir(...)' while passing on CI.
  • The combined character vector was empty because capture.output(print(res), type = "message") taps stderr, but interactive R sessions (RStudio, knitr) sometimes install a cli.default_handler that re-routes the message before it reaches stderr.
  • Fix forces cli.default_handler = NULL for the test scope via withr::local_options() and reads cli output through testthat::capture_messages(), which uses withCallingHandlers() to catch the message condition directly. Verified the new test passes both under default env AND under a session that pre-installs a hostile cli.default_handler that swallows everything (a stronger version of the failure mode the user hit). Confirmed the OLD test fails with the exact same error messages reported when run under that hostile env.

Test plan

  • Rscript -e 'pkgload::load_all("."); testthat::test_dir("tests/testthat", filter="v0952")' -> 18/18 pass
  • Same command with options(cli.default_handler = function(msg) invisible(NULL)) pre-installed -> 18/18 pass on the new test (and 16/18 on the old test, matching the original failure report)
  • Full test suite -> 0 failures, 22 expected skips (network/missing-pkg gates)
  • CI green on this PR

🤖 Generated with Claude Code

The two assertions on lines 86-87 of tests/testthat/test-v0952-vignette-pt.R
captured cli output via capture.output(type = "message"). That taps stderr,
which works in non-interactive R (CI) but silently returns empty when an
interactive session (RStudio, knitr renderer) has installed a custom
cli.default_handler that re-routes the message before it reaches stderr.
combined ended up empty and grepl("AC", combined) / grepl("CM", combined)
returned FALSE.

Force the default cli handler off via withr::local_options() and capture
the cli stream with testthat::capture_messages(), which uses
withCallingHandlers() to intercept the message condition directly. The
test now passes under both modes -- including a session that pre-installs
a hostile cli.default_handler -- while CI remains green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant